import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

// 1. 职工类，实现 Comparable 接口
class Employee implements Comparable<Employee> {
    private int id; // 职工编号
    private String name; // 姓名
    private String gender; // 性别
    private int groupPerformance; // 团体险业绩
    private int individualPerformance; // 个体险业绩

    // 不带参数的构造方法
    public Employee() {}

    // 带参数的构造方法
    public Employee(int id, String name, String gender, int groupPerformance, int individualPerformance) {
        this.id = id;
        this.name = name;
        this.gender = gender;
        this.groupPerformance = groupPerformance;
        this.individualPerformance = individualPerformance;
    }

    // Getter 和 Setter 方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public int getGroupPerformance() {
        return groupPerformance;
    }

    public void setGroupPerformance(int groupPerformance) {
        this.groupPerformance = groupPerformance;
    }

    public int getIndividualPerformance() {
        return individualPerformance;
    }

    public void setIndividualPerformance(int individualPerformance) {
        this.individualPerformance = individualPerformance;
    }

    // 计算总业绩
    public int getTotalPerformance() {
        return groupPerformance + individualPerformance;
    }

    // 实现 Comparable 接口，按总业绩升序排序
    @Override
    public int compareTo(Employee other) {
        return Integer.compare(this.getTotalPerformance(), other.getTotalPerformance());
    }

    // 格式化输出职工信息
    @Override
    public String toString() {
        return id + "," + groupPerformance + "," + individualPerformance + "," + name + "," + gender;
    }
}

// 2. 比较器类，实现 Comparator 接口，按团体险业绩升序排序
class GroupPerformanceComparator implements Comparator<Employee> {
    @Override
    public int compare(Employee e1, Employee e2) {
        return Integer.compare(e1.getGroupPerformance(), e2.getGroupPerformance());
    }
}

// 3. Main 类
public class Main {
    public static void main(String[] args) {
        // 创建职工线性表
        ArrayList<Employee> employees = new ArrayList<>();

        // 初始化职工数据
        employees.add(new Employee(1, "职工1", "female", 500, 400));
        employees.add(new Employee(2, "职工2", "female", 400, 600));
        employees.add(new Employee(3, "职工3", "male", 600, 300));
        employees.add(new Employee(4, "职工4", "female", 800, 200));
        employees.add(new Employee(5, "职工5", "male", 500, 700));

        // 输出表头
        System.out.println("编号,团险,个险,姓名,性别");

        // 按照总业绩升序排序
        Collections.sort(employees);
        for (Employee employee : employees) {
            System.out.println(employee);
        }

        // 输出空行分隔
        System.out.println();

        // 输出表头
        System.out.println("编号,团险,个险,姓名,性别");

        // 按照团体险业绩升序排序
        Collections.sort(employees, new GroupPerformanceComparator());
        for (Employee employee : employees) {
            System.out.println(employee);
        }
    }
}